import {Component} from '@angular/core';
import {SideNavService} from "../../service/side-nav.service";
import {VisitsService} from "../../service/visits.service";
import {Subscription} from "rxjs";
import {animate, state, style, transition, trigger} from "@angular/animations";
import {SalesService} from "../../service/sales.service";

@Component({
    selector: 'app-manager-index',
    templateUrl: './manager-index.component.html',
    styleUrls: ["../../../assets/css/manager/bootstrap.css",
        "../../../assets/css/manager/font-awesome.css",
        "../../../assets/css/manager/morris-0.4.3.min.css",
        "../../../assets/css/manager/custom-styles.css",
        "../../../assets/css/manager/google.css"
    ],
    animations: [
        trigger('openClose', [
            // ...
            state('open', style({
                marginLeft: '260px',
            })),
            state('closed', style({
                marginLeft: '0px',
            })),
            transition('open => closed', [
                animate('0.3s ease-in-out')
            ]),
            transition('closed => open', [
                animate('0.3s ease-in-out')
            ]),
        ]),
    ],
})
export class ManagerIndexComponent {
    isSideNavClosed = false;
    private subscription: Subscription;
    dailyVisits: number | undefined = 0;
    totalVisits: number | undefined = 0;
    sales = 0;

    constructor(private sideNavService: SideNavService,
                private visitService: VisitsService,
                private salesService: SalesService) {
        this.subscription = this.sideNavService.isSideNavClosed$.subscribe(isClosed => {
            this.isSideNavClosed = isClosed;
        });
    }

    ngOnInit() {
        this.visitService.getVisits().subscribe(result => {
            this.dailyVisits = result?.data?.DailyVisits;
            this.totalVisits = result?.data?.TotalVisits;
        });
        this.salesService.getSales().subscribe(result => {
            this.sales = result?.data?.Sales;
        });
    }
}
